package com.demo.modules.mq.rabbit.configuration;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 路由关键字过滤，支持模糊值， *:1个单词 #:0或多个单词
 *
 * @author MyPC
 */
@Configuration
public class TopicConfiguration {

    /**
     * 声明一个topic类型的交换机
     *
     * @return
     */
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("wr.topic");
    }

    /**
     * 声明一个队列
     *
     * @return
     */
    @Bean
    public Queue queue07() {
        return new Queue("topic.queue07");
    }

    /**
     * 声明一个队列
     *
     * @return
     */
    @Bean
    public Queue queue08() {
        return new Queue("topic.queue08");
    }

    /**
     * 绑定交换机和队列
     *
     * @param topicExchange
     * @param queue07
     * @return
     */
    @Bean
    public Binding binding07(TopicExchange topicExchange, Queue queue07) {
        //创建绑定关系，并且声明模糊过滤字符
        //*表示一个单词
        return BindingBuilder.bind(queue07).to(topicExchange).with("*");
    }

    /**
     * 绑定交换机和队列
     *
     * @param topicExchange
     * @param queue08
     * @return
     */
    @Bean
    public Binding binding08(TopicExchange topicExchange, Queue queue08) {
        //创建绑定关系，并且声明模糊过滤字符
        // #表示任意个单词
        return BindingBuilder.bind(queue08).to(topicExchange).with("#");
    }
}
